import { UserFileAPI } from '@/request/api';
export default {
    namespaced: true,
    state: {
        //购物车数量
        cartTotal: 0,
        userInfo: {
            // 昵称
            nickName: '--',
            coin: '0',
            headImg: require('@/assets/img/userImg.f8bbec5e.png'),
        },
    },
    mutations: {
        updateUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal;
            state.userInfo = payload.userInfo;
            console.log(payload.userInfo.nickName);
        },
        initUserInfo(state, payload) {
            state.cartTotal = 0;
            state.userInfo = {
                // 昵称
                nickName: '--',
                coin: '0',
                headImg: require('@/assets/img/userImg.f8bbec5e.png'),
            };
        },
    },
    actions: {
        async asyncUpdateUserInfo(context) {
            //发起请求，获取数据，更新到vuex中
            let res = await UserFileAPI();
            context.commit('updateUserInfo', res.data);
        },
    },
};
